package com.hntest.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hntest.entity.Pager;
import com.hntest.entity.RealAuth;
import com.hntest.entity.Student;
import com.hntest.service.impl.RealAuthServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller("realAuthController")
public class RealAuthController {
    @Autowired
    private RealAuthServiceImpl realAuthService;

    public void setRealAuthService(RealAuthServiceImpl realAuthService) {
        this.realAuthService = realAuthService;
    }

    @RequestMapping(value = "/admin/realAuthselect", method = {RequestMethod.GET, RequestMethod.POST})
    public String select(Pager pager, RealAuth realauth, ModelMap modelMap, HttpServletRequest request){
        String time1=request.getParameter("time1");
        String time2=request.getParameter("time2");
        List<RealAuth> list=realAuthService.getListByPage(pager, realauth,time1,time2);

        System.out.println("-----------------"+list);
        modelMap.put("list", list);
        modelMap.put("pager",pager);
        modelMap.put("realauth",realauth);
        modelMap.put("time1",time1);
        modelMap.put("time2",time2);
        return "admin/realAuthselect";
    }

    @RequestMapping(value = "/admin/realAuthUpdate",method= {RequestMethod.GET,RequestMethod.POST},
            produces= {"application/JSON;charset=utf-8"})//提交更新后的数据，成功后重定向到分页查询
    @ResponseBody
    public Object Update(RealAuth realAuth){
        System.out.println(realAuth);
        int n =  realAuthService.update(realAuth);
        RealAuth realAuth1 = null;
        JSONObject jsonObject = new JSONObject();
        if (n>0){
            realAuth1 = realAuthService.getRealAuthById(realAuth.getRealauthId());
            jsonObject.put("success",true);
        }else{
            jsonObject.put("success",false);
            jsonObject.put("msg","系统异常，审核出错");
        }
        jsonObject.put("msg",realAuth1.getStateDisplay());
        return JSON.toJSONString(jsonObject);
    }
}
